//
//  SDKEntryBoneKit.m
//  BoneKitDemo
//
//  Created by dujin on 2017/11/17.
//  Copyright © 2017年 Alibaba. All rights reserved.
//

#import "SDKEntryBoneKit.h"
#import <UIKit/UIKit.h>

#import <IMSBoneKit/IMSBoneConfiguration.h>

static NSString *const KLastBoneDebugIPKey = @"LastBoneDebugIPKey";
static NSString *const KBonePluginEnvironmentKey = @"KBonePluginEnvironmentKey";

@protocol IMSSDKEntryProtocol<NSObject>

@required
+ (NSDictionary *)getSDKDisplayConfig;
+ (void)didSelected:(NSNumber *)selectedIndex from:(UINavigationController *)navigation;
+ (float)getInitLevel;
+ (void)SDKEntryInit;

@end

@interface SDKEntryBoneKit ()<IMSSDKEntryProtocol>

@end

@implementation SDKEntryBoneKit

+ (NSDictionary *)getSDKDisplayConfig {
    return @{@"DisplayName" : @"Bone Mobile 容器 SDK",
             @"Actions" : @[ @"API列表", @"组件列表", @"环境切换", @"本地调试" ],
             @"OnlineStatus" : [self serverStatus],
             @"DisplayLevel" : @"0"};
}

+ (void)didSelected:(NSNumber *)selectedIndex from:(UINavigationController *)navigation {
}

+ (void)SDKEntryInit {
    IMSBoneConfiguration *configuration = [IMSBoneConfiguration sharedInstance];

    NSString *env = [SDKEntryBoneKit getPluginEnvironment];
    if (env.length == 0) {
        env = @"test";
        [SDKEntryBoneKit setPluginEnvironment:@"test"];
    }
    if ([env isEqualToString:@"test"]) {
        configuration.pluginEnvironment = IMSBonePluginEnvironmentDaily;
    } else {
        configuration.pluginEnvironment = IMSBonePluginEnvironmentRelease;
    }
}

+ (float)getInitLevel {
    return 2.3;
}

+ (NSString *)serverStatus {
    NSString *env = [SDKEntryBoneKit getPluginEnvironment];
    if ([env isEqualToString:@"test"]) {
        return @"开发环境";
    } else if ([env isEqualToString:@"release"]) {
        return @"生产环境";
    }
    return @"";
}

#pragma mark - Environment

+ (NSString *)getPluginEnvironment {
    return [[NSUserDefaults standardUserDefaults] objectForKey:KBonePluginEnvironmentKey];
}

+ (void)setPluginEnvironment:(NSString *)environment {
    if ([@[ @"test", @"release" ] containsObject:environment]) {
        [[NSUserDefaults standardUserDefaults] setObject:environment forKey:KBonePluginEnvironmentKey];
        [[NSUserDefaults standardUserDefaults] synchronize];
    }
}

@end
